import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';


/// 通用工具类
class WJCommonTool {
  /// 计算文字宽度
  static double getTextWidth(String text, TextStyle textStyle) {
    TextPainter painter = TextPainter();
    painter.text = TextSpan(style: textStyle, text: text);
    painter.maxLines = 1;
    painter.textDirection = TextDirection.ltr;
    painter.layout();
    return painter.size.width;
  }

  // 打开浏览器
  static Future<void> openBrowser(String uri) async {
    final Uri url = Uri.parse(uri);

    if (!await launchUrl(url)) {
      throw Exception('Could not launch $url');
    }
  }


// // 检查是否需要弹起app评价
// static Future<void> checkShouldShowAppReview() async {
//   var showAppReview = SharedPreferencesUtil.getBool(CommonConst.SP_KEY_APP_REVIEW, defaultValue: true);
//   if (showAppReview) {
//     final InAppReview inAppReview = InAppReview.instance;
//     if (await inAppReview.isAvailable()) {
//       inAppReview.requestReview();
//       SharedPreferencesUtil.setBool(CommonConst.SP_KEY_APP_REVIEW, false);
//     }
//   }
// }
}
